<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="https://www.thymeleaf.org">
<head>
    <title>房间管理</title>
    <meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" type="text/css" media="all" href="/css/bootstrap.css">
    <link rel="stylesheet" type="text/css" media="all" href="/layui/css/layui.css">
    <script type="text/javascript" src="/js/jquery-3.6.0.js"></script>
    <script type="text/javascript" src="/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="/layui/layui.js"></script>
</head>
<script>
    function typeValues(type) {
        $("#roomType").val(type);
    }
    function updateValues(ID){
        $("#UpdateID").val(ID);
    }
    function deleteValues(ID){
        $("#DeleteID").val(ID);
    }
    function SearchRoom() {
        var roomInfo = $("#roomSearch").val();
        data = {
            roomInfo: roomInfo
        }
        $.ajax({
            url:"/roomSearch",
            type: "Post",
            data: data,
            datatype: "html",
            success: function (data, status) {
                $("#roomInformation").replaceWith(data);
            }
        })
    }
    function selectIntoRoom(ID) {
        data = {
            id: ID
        }
        $.ajax({
            url:"findIntoRoom",
            type: "Post",
            data: data,
            datatype: "html",
            success: function (data, status) {
                $("#roomInformation").replaceWith(data);
            }
        })
    }
    function FindRoomType() {
        var type = $("#roomType").val();
        data = {
            type: type
        }
        $.ajax({
            url: "/roomType",
            type: "Post",
            data: data,
            datatype: "html",
            success: function(data, status) {
                $("#roomInformation").replaceWith(data);
            }
        })
    }
    function FindRoomState() {
        var state = $("#roomState").val();
        data = {
            state: state
        }
        $.ajax({
            url: "/roomState",
            type: "Post",
            data: data,
            datatype: "html",
            success: function(data, status) {
                $("#roomInformation").replaceWith(data);
            }
        })
    }
    function FindRoomCount() {
        var roomC = $("#roomCount").val();
        data = {
            roomC: roomC
        }
        $.ajax({
            url: "/roomCount",
            type: "Post",
            data: data,
            datatype: "html",
            success: function(data, status) {
                $("#roomInformation").replaceWith(data);
            }
        })
    }
    function AddRoom(){
        var name = $("#AddName").val();
        var cost = $("#AddCost").val();
        var type = $("#AddType").val();
        var maxCount = $("#AddMaxCount").val();
        data = {
            name: name,
            cost: cost,
            type: type,
            maxCount: maxCount
        }
        $.ajax({
            url:"/room/insertRoom",
            type: "Post",
            data:data,
            datatype: "html",
            success: function(data, status) {
                $("#roomInformation").replaceWith(data);
            }
        })
        setTimeout(function () {
            location.reload();
        }, 3000);
    }
    function UpdateRoom() {
        var id = $("#UpdateID").val();
        var cost = $("#UpdateCost").val();
        data = {
            id: id,
            cost: cost
        }
        $.ajax({
            url: "/room/updateRoom",
            type: "Post",
            data: data,
            datatype: "html",
            success: function (data,status) {
                $("#roomInformation").replaceWith(data);
            }
        })
        setTimeout(function () {
            location.reload();
        }, 3000);
    }
    function DeleteRoom() {
        var id = $("#DeleteID").val();
        data = {
            id: id
        }
        $.ajax({
            url: "room/deleteRoom",
            type: "Post",
            data: data,
            datatype: "html",
            success: function (data,status) {
                $("#roomInformation").replaceWith(data);
            }
        })
        setTimeout(function () {
            location.reload();
        }, 3000);
    }
</script>
<body>
<div class="container mt-3" id="roomInformation">
    <h2>房间管理界面</h2>
    <br>
    <ul class="nav nav-pills" role="tablist">
        <li class="navbar-form navbar-left" role="search">
            <a class="form-group">
                <input type="text" class="form-control" id="roomSearch" placeholder="搜索相关房间"/>
            </a>
        </li>
        <li><button type="submit" class="btn btn-default" onclick="SearchRoom()">搜索</button></li>
        <div class="roomtype">
            <select id="roomType" onchange="FindRoomType()" type="button" class="btn btn-light btn-sm">
                <option>按类型筛选</option>
                <option value="all">全部</option>
                <option value="街机">街机</option>
                <option value="Switch">Switch</option>
                <option value="PS4">PS4</option>
                <option value="PS5">PS5</option>
                <option value="龙与地下城跑团">龙与地下城跑团</option>
                <option value="克苏鲁神话跑团">克苏鲁神话跑团</option>
                <option value="跑团">跑团</option>
                <option value="狼人杀">狼人杀</option>
                <option value="三国杀">三国杀</option>
                <option value="桌游">桌游</option>
                <option value="剧本杀">剧本杀</option>
            </select>
        </div>
        <div class="judge">
            <select id="roomState" onchange="FindRoomState()" type="button" class="btn btn-light btn-sm">
                <option>按房间状态筛选</option>
                <option value=77>全部</option>
                <option value=0>预约</option>
                <option value=1>开放</option>
            </select>
        </div>
        <div class="userInto">
            <select id="roomCount" onchange="FindRoomCount()" type="button" class="btn btn-light btn-sm">
                <option>按进入人数筛选</option>
                <option value=0>全部</option>
                <option value=1>1</option>
                <option value=2>2</option>
                <option value=3>3</option>
                <option value=4>4</option>
                <option value=5>5</option>
                <option value=6>6</option>
                <option value=7>7</option>
                <option value=8>8</option>
                <option value=9>9</option>
                <option value=10>10</option>
                <option value=11>11</option>
                <option value=12>12</option>
            </select>
        </div>

        <li class="pagination"><button type="button" class="btn btn-light btn-sm" data-bs-toggle="modal" data-bs-target="#add">添加房间</button></li>

    </ul>

    <div class="tab-content">
        <div id="home" class="container tab-pane active"><br>
            <table class="table table-bordered">
                <thead>
                <tr>
                    <th>房间号</th>
                    <th>房间名称</th>
                    <th>房间消费（元/时）</th>
                    <th>类型</th>
                    <th>当前人数</th>
                    <th>最大人数</th>
                    <th>权限状态</th>
                    <th>查看玩家</th>
                    <th>修改费用</th>
                    <th>删除房间</th>
                </tr>
                </thead>
                <tbody>
                <tr th:each="room:${rooms}">
                    <td th:text="${room.id}"></td>
                    <td th:text="${room.name}"></td>
                    <td th:text="${room.cost}"></td>
                    <td th:text="${room.type}"></td>
                    <td th:text="${room.count}"></td>
                    <td th:text="${room.maxCount}"></td>
                    <td th:if="${room.state}==1">开放</td>
                    <td th:if="${room.state}==0">预约</td>
                    <td><button type="button" class="btn btn-light btn-sm" data-bs-toggle="modal" data-bs-target="#select" th:onclick="|javascript:selectIntoRoom('${room.id}')|">查看</button></td>
                    <td><button type="button" class="btn btn-light btn-sm" data-bs-toggle="modal" data-bs-target="#modify" th:onclick="|javascript:updateValues('${room.id}')|">修改</button></td>
                    <td><button type="button" class="btn btn-light btn-sm" data-bs-toggle="modal" data-bs-target="#fire" th:onclick="|javascript:deleteValues('${room.id}')|">删除</button></td>
                </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>
<div class="modal Add" id="add">
    <div class="modal-dialog modal-lg">
        <div class="modal-content" style="width:650px">

            <div class="modal-header">
                <h3 class="modal-title">房间信息</h3>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>

            <div class="modal-body">
                <table class="table table-borderless">
                    <tr>
                        <td style="font-size:22px">房间名</td><td><input id="AddName" name="AddName" placeholder="请输入房间名" style="height:32px;width:300px;font-size:22px"></td>
                    </tr>
                    <tr>
                        <td style="font-size:22px">房间费用</td><td><input id="AddCost" name="AddCost" placeholder="请输入房间费用（元/时）" style="height:32px;width:300px;font-size:22px"></td>
                    </tr>
                    <tr>
                        <td style="font-size:22px">类型</td><td><input id="AddType" name="AddType" placeholder="请输入房间类型" style="height:32px;width:300px;font-size:22px"></td>
                    </tr>
                    <tr>
                        <td style="font-size:22px">最大人数</td><td><input id="AddMaxCount" name="AddMaxCount" placeholder="请输入游玩最大人数" style="height:32px;width:300px;font-size:22px"></td>
                    </tr>
                </table>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-danger" data-bs-dismiss="modal" onclick="AddRoom()">确定</button>
            </div>

        </div>
    </div>
</div>
<div class="modal alter" id="modify">
    <div class="modal-dialog modal-lg">
        <div class="modal-content" style="width:650px">

            <div class="modal-header">
                <h3 class="modal-title">房间信息</h3>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>

            <div class="modal-body">
                <table class="table table-bordered">
                    <thead>
                    </thead>
                    <tbody>
                    <tr>
                        <td style="font-size:22px">房间号</td><td><input readonly="readonly" id="UpdateID" name="UpdateID" style="height:32px;width:300px;font-size:22px"></td>
                    </tr>
                    <tr>
                        <td style="font-size:22px">房间费用</td><td><input id="UpdateCost" name="UpdateCost" style="height:32px;width:300px;font-size:22px"></td>
                    </tr>
                    </tbody>
                </table>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-danger" data-bs-dismiss="modal" onclick="UpdateRoom()">确定</button>
            </div>

        </div>
    </div>
</div>
<div class="modal Fire" id="fire">
    <div class="modal-dialog modal-lg">
        <div class="modal-content" style="width:650px">

            <div class="modal-header">
                <h3 class="modal-title">删除房间</h3>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>

            <div class="modal-body">
                <table class="table table-bordered">
                    <thead>
                    </thead>
                    <tbody>
                    <tr>
                        <td style="font-size:22px">房间号</td><td><input readonly="readonly" id="DeleteID" name="DeleteID" style="height:32px;width:300px;font-size:22px"></td>
                    </tr>
                    <tr>
                        <td style="font-size:22px">是否删除该房间？</td><td style="height:32px;width:300px;font-size:22px">永久删除该房间（真的很久）</td>
                    </tr>
                    </tbody>
                </table>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-danger" data-bs-dismiss="modal" onclick="DeleteRoom()">是</button>
            </div>

        </div>
    </div>
</div>
</body>
</html>